package cn.com.winning.ecare.activity;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import cn.com.winning.ecare.common.Grideviewmenu;
import cn.com.winning.ecare.common.MyApplication;
import cn.com.winning.ecare.utils.HTTPGetTool;
import cn.com.winning.ecare.utils.SlidingLayout;
import cn.com.winning.ecare.utils.URLUtils;
import cn.com.winning.ecare.utils.UserRecord;
import cn.com.winning.ecare.widgets.CustomProgressDialog;

/**
 * 挂号主界面
 * @author Administrator
 *
 */
public class GhOne extends Activity
{
	private RelativeLayout kslv;
	private Button nextbutton;
	private GhOne oThis = this;
	private CustomProgressDialog proDialog;// 加载框
	private TextView text_yy, text_ksmc, text_ksid;
	MyApplication myApp;

	/**
	 * 侧滑布局对象，用于通过手指滑动将左侧的菜单布局进行显示或隐藏。
	 */
	private SlidingLayout slidingLayout;

	private LinearLayout content;
	Grideviewmenu gm;
	private GridView gridView;
	/**
	 * menu按钮，点击按钮展示左侧布局，再点击一次隐藏左侧布局。
	 */
	private ImageButton menuButton;
	private ImageButton mainselected;
	private TextView nametv, tv;
	private ImageView menu_img;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.gh_one);
		myApp = (MyApplication) getApplication();
		myApp.addActivity(this);
		// 设置滑动菜单
		initSliding();
		// 初始化view
		findView();

		// 点击事件
		setOnClick();
		
		myApp.getUserRecords().setUsername(myApp.getAccount());
		myApp.getUserRecords().setModule("GhOne@预约挂号");
		UserRecord.getInstance(myApp.getUserRecords()).init();
	}

	private void initSliding()
	{
		menuButton = (ImageButton) findViewById(R.id.menuButton);
		menuButton.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				
				oThis.onBackPressed();
			}
		});
		
	}

	private void setOnClick()
	{
		kslv.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				Intent intent = new Intent(oThis, GhTwo.class);
				intent.putExtra("yy_id", myApp.getYydm());
				oThis.startActivityForResult(intent, 1);

			}
		});

		nextbutton.setOnClickListener(new View.OnClickListener()
		{

			@Override
			public void onClick(View v)
			{
				// TODO Auto-generated method stub
				if (text_ksid.getText() != null && !text_ksid.getText().equals(""))
				{
					Intent intent = new Intent(oThis, GhThree.class);
					intent.putExtra("ks_id", text_ksid.getText().toString());
					startActivity(intent);
				}
				else
				{
					Toast.makeText(oThis, "请选择科室", Toast.LENGTH_SHORT).show();
				}

			}
		});

		menu_img.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View view)
			{
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(oThis, GhSeven.class);
				startActivity(intent);
			}
		});
		mainselected.setOnClickListener(new OnClickListener()
		{

			@Override
			public void onClick(View view)
			{
				// TODO Auto-generated method stub
				Intent intent = new Intent();
				intent.setClass(oThis, Mainmean.class);
				startActivity(intent);
				oThis.finish();
			}
		});
	}

	private void findView()
	{
		kslv = (RelativeLayout) this.findViewById(R.id.lv_ks);
		nextbutton = (Button) this.findViewById(R.id.next_button);
		text_ksmc = (TextView) this.findViewById(R.id.text_ksmc);
		text_ksid = (TextView) this.findViewById(R.id.text_ksid);
		text_yy = (TextView) this.findViewById(R.id.text_yy);
		text_yy.setText(myApp.getYymc());
		menu_img = (ImageView) this.findViewById(R.id.menu_yy_img);
		mainselected = (ImageButton) this.findViewById(R.id.mainselected);
	}

	/*
	 * (non-Javadoc) 得到传回的ks
	 * 
	 * @see android.app.Activity#onActivityResult(int, int,
	 * android.content.Intent)
	 */
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data)
	{
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		String ks_mc = data.getStringExtra("ks_mc") == null ? "" : data.getStringExtra("ks_mc");// 取出传回来的数据
		String ks_id = data.getStringExtra("ks_id") == null ? "" : data.getStringExtra("ks_id");
		if (!ks_id.equals(""))
		{
			text_ksmc.setText(ks_mc + " ");
			text_ksid.setText(ks_id);
		}

	}

}
